<template>
	<view class="container">
		<view class="bg-white">
			<view class="text-13 padding flex justify-between align-center solid-bottom">
				<view class="text-333">
					竞标金额
				</view>
				<view class="color flex justify-end align-center">
					<input type="number" value="" v-model="orderServiceCompetitiveDetailDto.competitivePrice" class="text-13 flex-treble" />
					<view class="">
						元
					</view>
				</view>
			</view>
			<view class="text-13 padding flex justify-between align-center solid-bottom">
				<view class="text-333">
					竞标方案
				</view>
				<view class="flex justify-start align-center" @click="onUpload">
					<view class="text-767696">
						{{Bidding}}
					</view>
					<view class="cuIcon-right lg margin-left-xs">

					</view>
				</view>
			</view>
			<view class="text-13 padding flex justify-between align-center">
				<view class="text-333">
					详细描述
				</view>
				<input type="text" v-model="orderServiceCompetitiveDetailDto.content" value="" class="text-center flex-treble"
					placeholder="在这里描述下您的竞标说明" />
			</view>
		</view>
		<l-file top="350rpx" ref="lFile" @up-success="onSuccess"></l-file>
		<button @click="submit" class="bg-color padding text-white radius10 margin-left-sm margin-right-sm btn text-15">确定</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: this.$config.baseUrl,
				orderServiceCompetitiveDetailDto: {
					"appendix": "",
					"competitivePrice": '',
					"content": "",
					"orderServiceId":""
				},
				Bidding:'选择上传竞标方案'
			};
		},
		onLoad(options) {
			// console.log(options)
			if(options.orderServiceId) this.orderServiceCompetitiveDetailDto.orderServiceId = options.orderServiceId
		},
		methods: {
			async submit() {
				
				for (let i in this.orderServiceCompetitiveDetailDto) {
					
					if(!this.orderServiceCompetitiveDetailDto[i]){
						// console.log(i)
						this.$util.msg('请完善数据')
						return
					}
				} 
				this.orderServiceCompetitiveDetailDto.competitivePrice = this.orderServiceCompetitiveDetailDto.competitivePrice*100
				
				// console.log('111111111111' + JSON.stringify(this.orderServiceCompetitiveDetailDto))
				const [err, res] = await this.$post(this.$api.orderService_addDe,this.orderServiceCompetitiveDetailDto)
				if (res) {
					
						this.$util.msg(res.message)
						setTimeout(()=>{
							uni.navigateBack()
						},1500)
					// console.log(res)

				}
			},
			onUpload() {
				/**
				 * currentWebview: 当前webview
				 * url：上传接口地址
				 * name：附件key,服务端根据key值获取文件流，默认file,上传文件的key
				 * header: 上传接口请求头
				 */
				this.$refs.lFile.upload({
					// #ifdef APP-PLUS
					// nvue页面使用时请查阅nvue获取当前webview的api，当前示例为vue窗口
					currentWebview: this.$mp.page.$getAppWebview(),
					// #endif
					url: this.$api.upload,
					name: 'file',
					header: {
						Authorization:'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJ0ZXN0Iiwic2NvcGUiOlsiYWxsIl0sImlkIjoxLCJleHAiOjE2MTA2MTA4OTMsImF1dGhvcml0aWVzIjpbIuWJjeWPsOS8muWRmCJdLCJqdGkiOiJjNTAwYTQzMy04ODVkLTRkOTctYTZjYy1iNDVmYjVkMmVmMzgiLCJjbGllbnRfaWQiOiJwb3J0YWwtYXBwIn0.j7U3u7X37obI98qyvDr8OyCRupkk401kK-7zGuJexT7UKFF8gXTAfWmBjafRMjmuuCqSM-MPLQPQL1Cq8Fzj6bgS6D5Vq9TbVQ43CyE2mLU415CVlyfH0JJ35vRCj_zlgDp7SsW_ichocwfqSo0h0QlaQ6kSsXgktxpMLULIEYI'
					}
					// header: {'Authorization':'token'},
					// 其他业务参数直接写key,value,如：
					// key1: 'value1',
					// key2: 'value2',
				});
			},
			onSuccess(res) {
				
				// console.log('上传成功回调',JSON.stringify(res));
				// #ifdef MP-WEIXIN
				if(res.data.code==200){
					this.orderServiceCompetitiveDetailDto.appendix = res.data.data
					this.Bidding = '已上传竞标方案'
				}
				// #endif
				// #ifdef APP-PLUS
				const data =  JSON.parse(res.data.id)
				  if(data.code==200){
					  console.log(1111)
					  this.orderServiceCompetitiveDetailDto.appendix = data.data
					  this.Bidding = '已上传竞标方案'
				  }
				
					// #endif
				
				// uni.showToast({
				// 	title: JSON.stringify(res),
				// 	icon: 'none'
				// })
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btn {
		margin-top: 162rpx;
	}
</style>
